using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using Entities;
/// <summary>
/// Summary description for HocVienDAL
/// </summary>
namespace DataAccess 
{
    
    public class HocVienDAL  : BaseDAL
    {
    	#region Private Variables

		#endregion
		
 #region Public Constructors
        public HocVienDAL()
        {
            //
            // TODO: Add constructor logic here
            //
            
        }
 #endregion       

	
		
#region Public Methods
        public int Insert(HocVien objHocVien)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "HocVien_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@KhoaDoiTuongGhiDanh", SqlDbType.BigInt);
Sqlparam.Value = objHocVien.KhoaDoiTuongGhiDanh;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@KhoaHoc", SqlDbType.BigInt);
Sqlparam.Value = objHocVien.KhoaHoc;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@HangXe", SqlDbType.BigInt);
Sqlparam.Value = objHocVien.HangXe;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
Sqlparam.Direction = ParameterDirection.ReturnValue;
Sqlcomm.Parameters.Add(Sqlparam);

           
            int result =base.ExecuteNoneQuery(Sqlcomm);
            
            if(!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
				result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(HocVien objHocVien)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "HocVien_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Khoa", SqlDbType.BigInt);
Sqlparam.Value = objHocVien.Khoa;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@KhoaDoiTuongGhiDanh", SqlDbType.BigInt);
Sqlparam.Value = objHocVien.KhoaDoiTuongGhiDanh;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@KhoaHoc", SqlDbType.BigInt);
Sqlparam.Value = objHocVien.KhoaHoc;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@HangXe", SqlDbType.BigInt);
Sqlparam.Value = objHocVien.HangXe;
Sqlcomm.Parameters.Add(Sqlparam);


            
            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);
            
            int result=base.ExecuteNoneQuery(Sqlcomm);
            
             if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);
                
            return result;

           
        }

        public int Delete(HocVien objHocVien)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "HocVien_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Khoa", SqlDbType.BigInt);
Sqlparam.Value = objHocVien.Khoa;
Sqlcomm.Parameters.Add(Sqlparam);


            
            int result=base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

         public int DeleteAll()
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "HocVien_DeleteAll";

            int result=base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public HocVien Select(HocVien objHocVien)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "HocVien_GetByPK";
            SqlParameter Sqlparam;
  

            Sqlparam = new SqlParameter("@Khoa", SqlDbType.BigInt);
Sqlparam.Value = objHocVien.Khoa;
Sqlcomm.Parameters.Add(Sqlparam);


            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if(!Convert.IsDBNull(dr["Khoa"]))
objHocVien.Khoa=Convert.ToInt64(dr["Khoa"]);
if(!Convert.IsDBNull(dr["KhoaDoiTuongGhiDanh"]))
objHocVien.KhoaDoiTuongGhiDanh=Convert.ToInt64(dr["KhoaDoiTuongGhiDanh"]);
if(!Convert.IsDBNull(dr["KhoaHoc"]))
objHocVien.KhoaHoc=Convert.ToInt64(dr["KhoaHoc"]);
if(!Convert.IsDBNull(dr["HangXe"]))
objHocVien.HangXe=Convert.ToInt64(dr["HangXe"]);

            }
             return objHocVien;
        }

        public ArrayList SelectAllToArray( )
        {
			
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "HocVien_GetAll";
            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrHocVien = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach(DataRow dr in dt.Rows)
{
HocVien objHocVien= new HocVien();
if(!Convert.IsDBNull(dr["Khoa"]))
objHocVien.Khoa=Convert.ToInt64(dr["Khoa"]);
if(!Convert.IsDBNull(dr["KhoaDoiTuongGhiDanh"]))
objHocVien.KhoaDoiTuongGhiDanh=Convert.ToInt64(dr["KhoaDoiTuongGhiDanh"]);
if(!Convert.IsDBNull(dr["KhoaHoc"]))
objHocVien.KhoaHoc=Convert.ToInt64(dr["KhoaHoc"]);
if(!Convert.IsDBNull(dr["HangXe"]))
objHocVien.HangXe=Convert.ToInt64(dr["HangXe"]);
arrHocVien.Add(objHocVien);
}
            }
               return arrHocVien;
        }
        
        public DataTable SelectAll( )
        {
			
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "HocVien_GetAll";
            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
          
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                
            }
               return dt;
        }

     
#endregion          
    
    }

}
